package com.shenhan.lock8;

import lombok.SneakyThrows;

import java.util.concurrent.TimeUnit;

/**
 * @author shenhan
 * @create 2020/6/10 15:52
 * @description 8锁，就是关于锁的8个问题
 * 3、加入静态同步方法后，两个线程先打印发短信还是先打电话？     1、发短信  这次锁的对象是Class对象，因为静态代码调用。
 */
public class Test3 {
    public static void main(String[] args) throws InterruptedException {
//        Phone3 phone1 = new Phone3();

        new Thread(Phone3::sendMessage, "A").start();
        TimeUnit.SECONDS.sleep(1L);
//        new Thread(Phone3::call, "B").start();
        new Thread(Phone3::call, "B").start();
    }
}

class Phone3 {
    @SneakyThrows
    public static synchronized void sendMessage() {
        TimeUnit.SECONDS.sleep(4L);
        System.out.println(Thread.currentThread().getName() + " 发短信");
    }

    public static synchronized void call() {
        System.out.println(Thread.currentThread().getName() + " 打电话");
    }
}
